using System.Collections;
using UnityEngine;

public class TRB_Hospital_FlashbackSequence : MonoBehaviour
{
	[Header("-= DEBUG =-")]
	public bool Debug_SkipIntroduction = true;

	[Header("-= Cutscene References =-")]
	public PlayerManager Kris;

	public Animator OriginalNoelle;

	[SerializeField]
	private AudioClip Music_FlashbackReprise;

	[SerializeField]
	private CameraManager playerCamera;

	[SerializeField]
	private TRB_FlashbackSequence_Chatbox FlashbackTextbox;

	[SerializeField]
	private TRB_Hospital_IntroductionCutscene HospitalLobbyCutscene;

	[SerializeField]
	private AudioSource FlashbackMusicSource;

	[SerializeField]
	private AudioClip mus_rumbling;

	[Header("-= Cutscene Chats =-")]
	[SerializeField]
	private CHATBOXTEXT[] CutsceneChats;

	[SerializeField]
	private CHATBOXTEXT[] FlashbackChats;

	[SerializeField]
	private AudioClip[] CutsceneSounds;

	[Header("-= Flashback References =-")]
	[Space(5f)]
	[Header("Shared")]
	[SerializeField]
	private SpriteRenderer Fade_Background;

	[Header("- Characters -")]
	[Space(5f)]
	[Header("Noelle")]
	[SerializeField]
	private SPR_CopyRenderer OriginalNoelle_Silhouette;

	[SerializeField]
	private Animator NoelleChild_Silhouette;

	[Header("Rudy")]
	[SerializeField]
	private Animator Rudy_Silhouette;

	[Space(5f)]
	[Header("- Environments -")]
	[Space(5f)]
	[SerializeField]
	private SpriteRenderer[] Flashback_School;

	[SerializeField]
	private GameObject Flashback_Snow_Holder;

	[SerializeField]
	private SpriteRenderer[] Flashback_Snow;

	[Header("- Environment Specific -")]
	[Header("Snow")]
	[SerializeField]
	private ParticleSystem Flashback_SnowParticle;

	[SerializeField]
	private Transform Flashback_Snowball;

	[SerializeField]
	private bool Flashback_Snow_BallRoll;

	[SerializeField]
	private float Flashback_Snowball_RollSpeed = 3f;

	[SerializeField]
	private Sprite[] Flashback_SnowballSprites;

	[Space(5f)]
	[SerializeField]
	private SpriteRenderer Flashback_Snowpile;

	[SerializeField]
	private Sprite[] Flashback_Snowpile_Sprites;

	[Space(5f)]
	[SerializeField]
	private Transform Flashback_Stick1;

	[SerializeField]
	private Transform Flashback_Stick2;

	[Header("Home")]
	[SerializeField]
	private SpriteRenderer[] Flashback_Home;

	[Header("Bed")]
	[SerializeField]
	private SpriteRenderer[] Flashback_Bed;

	[SerializeField]
	private GameObject Flashback_Bed_NoelleGuitarArms;

	[SerializeField]
	private Sprite Flashback_Bed_GuitarSprite;

	[Header("Present Day")]
	[SerializeField]
	private SpriteRenderer[] Flashback_PresentDay;

	[SerializeField]
	private Color[] RudySkinPale_Colors;

	[SerializeField]
	private int RudySkinIndex;

	[Header("Finale")]
	[SerializeField]
	private SpriteRenderer Finale_BackgroundFlash;

	[SerializeField]
	private Animator Fountain_InitialLight;

	[SerializeField]
	private SpriteRenderer Fountain_InnerBeam;

	[SerializeField]
	private ParticleSystem Fountain_CrackParticles;

	[SerializeField]
	private Animator Fountain_Noelle_Lit;

	[SerializeField]
	private Animator Fountain_Noelle_unlit;

	[SerializeField]
	private GameObject[] FountainTargetParticles;

	[SerializeField]
	private Animator Fountain_AngelHalo;

	[Header("Ending Story Panels")]
	[SerializeField]
	private SpriteRenderer StoryPanel_Fade;

	[SerializeField]
	private SpriteRenderer StoryPanel_Background;

	[SerializeField]
	private Sprite StoryPanel_Background_Inverted;

	[SerializeField]
	private GameObject StoryPanel_Fountain;

	[SerializeField]
	private TRB_FlashbackSequence_Chatbox GasterText;

	[SerializeField]
	private CHATBOXTEXT EndingText;

	[SerializeField]
	private Transform StoryPanel_DarknessBubbles;

	[HideInInspector]
	public bool Debug_IsPlayingFinale;

	private void Start()
	{
		Flashback_Snow_Holder.SetActive(value: false);
		if (Debug_SkipIntroduction)
		{
			Kris = PlayerManager.Instance;
			Kris._PlayerState = PlayerManager.PlayerState.Cutscene;
			Kris._PAnimation.CanUseBasePlayerAnimations = false;
			Kris._PMove._anim.SetBool("MOVING", value: true);
			LightworldMenu.Instance.CanOpenMenu = false;
			DarkworldMenu.Instance.CanOpenMenu = false;
			RotateNoelleToDirection(Vector2.up);
			OriginalNoelle.Play("IdleN");
			OriginalNoelle.transform.position = new Vector2(30f, -3.7f);
			OriginalNoelle.gameObject.SetActive(value: false);
			playerCamera.transform.position = new Vector3(30f, 0f, -10f);
		}
		if (!Debug_IsPlayingFinale)
		{
			StartCoroutine(Cutscene_PreFlashback());
		}
	}

	private void Update()
	{
		if (Flashback_Snow_BallRoll)
		{
			Flashback_Snowball.transform.rotation *= Quaternion.Euler(0f, 0f, Flashback_Snowball_RollSpeed * Time.deltaTime);
		}
		if (Input.GetKeyDown(KeyCode.J))
		{
			StartCoroutine(OpenFountain());
		}
	}

	private IEnumerator Cutscene_PreFlashback()
	{
		if (Debug_SkipIntroduction)
		{
			yield return new WaitForSeconds(0.5f);
		}
		yield return new WaitForSeconds(0.5f);
		OriginalNoelle.gameObject.SetActive(value: true);
		OriginalNoelle.SetBool("InCutscene", value: true);
		OriginalNoelle.speed = 0.85f;
		OriginalNoelle.Play("WalkN");
		NoelleChild_Silhouette.SetBool("InCutscene", value: true);
		RotateNoelleToDirection(Vector2.up);
		Rudy_Silhouette.SetBool("InCutscene", value: true);
		CutsceneUtils.MoveTransformLinear(OriginalNoelle.transform, new Vector2(30f, -0.5f), 2f);
		yield return new WaitForSeconds(2f);
		OriginalNoelle.Play("IdleN");
		yield return new WaitForSeconds(1f);
		RotateNoelleToDirection(Vector2.left);
		OriginalNoelle.Play("TRB_IdleParanoid");
		yield return new WaitForSeconds(0.5f);
		OriginalNoelle.Play("TRB_WalkParanoid");
		CutsceneUtils.MoveTransformLinear(OriginalNoelle.transform, new Vector2(28.55f, -0.5f), 1.25f);
		yield return new WaitForSeconds(1.25f);
		OriginalNoelle.Play("TRB_IdleParanoid");
		yield return new WaitForSeconds(0.35f);
		CutsceneUtils.RunFreshChat(CutsceneChats[0], 0, ForcePosition: true, OnBottom: true);
		while (ChatboxManager.Instance.ChatIsCurrentlyRunning)
		{
			yield return null;
		}
		yield return new WaitForSeconds(0.5f);
		CutsceneUtils.MoveTransformLinear(OriginalNoelle.transform, new Vector2(26.925f, -0.5f), 1f);
		OriginalNoelle.Play("TRB_WalkParanoid");
		yield return new WaitForSeconds(1f);
		OriginalNoelle.Play("TRB_IdleParanoid");
		yield return new WaitForSeconds(1f);
		RotateNoelleToDirection(Vector2.up);
		yield return new WaitForSeconds(1f);
		CutsceneUtils.RunFreshChat(CutsceneChats[0], 1, ForcePosition: true, OnBottom: true);
		while (ChatboxManager.Instance.ChatIsCurrentlyRunning)
		{
			yield return null;
		}
		yield return new WaitForSeconds(0.5f);
		OriginalNoelle.speed = 1f;
		OriginalNoelle.Play("TRB_WalkParanoid");
		NoelleChild_Silhouette.Play("Walk");
		CutsceneUtils.MoveTransformLinear(OriginalNoelle.transform, new Vector2(26.925f, 0.7f), 2f);
		CutsceneUtils.FadeInSprite(Fade_Background);
		OriginalNoelle_Silhouette.gameObject.GetComponent<SPR_CopyPosition>().enabled = true;
		CutsceneUtils.FadeInSprite(OriginalNoelle_Silhouette.Renderer, 0.5f);
		yield return new WaitForSeconds(2f);
		Vector3 cameraCenterPos = new Vector3(OriginalNoelle.transform.position.x, OriginalNoelle.transform.position.y, -10f);
		while (playerCamera.transform.position != cameraCenterPos)
		{
			yield return null;
			playerCamera.transform.position = Vector3.MoveTowards(playerCamera.transform.position, cameraCenterPos, 1.5f * Time.deltaTime);
		}
		yield return new WaitForSeconds(1f);
		OriginalNoelle.GetComponent<SpriteRenderer>().enabled = false;
		OriginalNoelle_Silhouette.gameObject.GetComponent<SPR_CopyPosition>().enabled = false;
		yield return new WaitForSeconds(0.45f);
		NoelleChild_Silhouette.transform.position = OriginalNoelle.transform.position;
		MusicManager.Instance.source.clip = null;
		MusicManager.PlaySong(Music_FlashbackReprise, FadePreviousSong: true, 3f, FlashbackMusicSource);
		GonerMenu.Instance.ShowMusicCredit("Flashback (Reprise)", "MagicFroge");
		CutsceneUtils.FadeOutSprite(OriginalNoelle_Silhouette.Renderer);
		CutsceneUtils.FadeInSprite(NoelleChild_Silhouette.GetComponent<SpriteRenderer>());
		StartCoroutine(Cutscene_FlashbackSchool());
	}

	private IEnumerator Cutscene_FlashbackSchool()
	{
		yield return new WaitForSeconds(1f);
		FlashbackTextbox.RunText(FlashbackChats[0], 0, 0);
		yield return new WaitForSeconds(3.5f);
		FlashbackTextbox.RunText(FlashbackChats[0], 1, 0);
		CutsceneUtils.MoveTransformLinear(playerCamera.transform, new Vector3(26.925f, 8.25f, -10f), 3.25f);
		CutsceneUtils.MoveTransformLinear(NoelleChild_Silhouette.transform, new Vector2(26.925f, 5.95f), 3.75f);
		yield return new WaitForSeconds(3.75f);
		FlashbackTextbox.EndText();
		NoelleChild_Silhouette.Play("Idle");
		yield return null;
		CutsceneUtils.ShakeTransform(NoelleChild_Silhouette.transform, 0.25f, 1f);
		yield return new WaitForSeconds(1.5f);
		NoelleChild_Silhouette.Play("IdleParanoid");
		RotateChildNoelleToDirection(Vector2.left);
		yield return new WaitForSeconds(1.25f);
		FlashbackTextbox.RunText(FlashbackChats[0], 2, 0);
		yield return new WaitForSeconds(2.5f);
		Rudy_Silhouette.Play("Cheer");
		RotateChildNoelleToDirection(Vector2.up);
		yield return new WaitForSeconds(1.65f);
		FlashbackTextbox.RunText(FlashbackChats[0], 3, 0);
		yield return new WaitForSeconds(0.825f);
		NoelleChild_Silhouette.Play("Walk");
		CutsceneUtils.MoveTransformLinear(NoelleChild_Silhouette.transform, new Vector2(26.925f, 9.95f), 4f);
		yield return new WaitForSeconds(2.5f);
		Rudy_Silhouette.Play("Idle");
		RotateRudyToDirection(Vector2.left);
		yield return new WaitForSeconds(0.85f);
		CutsceneUtils.FadeOutSprite(NoelleChild_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		CutsceneUtils.FadeOutSprite(Rudy_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		SpriteRenderer[] flashback_School = Flashback_School;
		for (int i = 0; i < flashback_School.Length; i++)
		{
			CutsceneUtils.FadeOutSprite(flashback_School[i], 2f);
		}
		yield return new WaitForSeconds(2f);
		FlashbackTextbox.EndText();
		StartCoroutine(Cutscene_FlashbackSnow());
	}

	private IEnumerator Cutscene_FlashbackSnow()
	{
		Flashback_Snow_Holder.SetActive(value: true);
		playerCamera.transform.position = new Vector3(26.925f, 25f, -10f);
		NoelleChild_Silhouette.transform.position = new Vector2(23.475f, 23.65f);
		Rudy_Silhouette.transform.position = new Vector2(31.175f, 23.65f);
		Rudy_Silhouette.Play("Beckon_Idle");
		NoelleChild_Silhouette.Play("Idle");
		RotateChildNoelleToDirection(Vector2.right);
		RotateRudyToDirection(Vector2.left);
		yield return null;
		yield return new WaitForSeconds(0.25f);
		FlashbackTextbox.RunText(FlashbackChats[1], 0, 0);
		SpriteRenderer[] flashback_Snow = Flashback_Snow;
		for (int i = 0; i < flashback_Snow.Length; i++)
		{
			CutsceneUtils.FadeInSprite(flashback_Snow[i], 2f);
		}
		CutsceneUtils.FadeInSprite(NoelleChild_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		CutsceneUtils.FadeInSprite(Rudy_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		yield return new WaitForSeconds(0.5f);
		yield return new WaitForSeconds(3f);
		Rudy_Silhouette.Play("Beckon");
		Flashback_Snow_BallRoll = true;
		NoelleChild_Silhouette.Play("Walk");
		NoelleChild_Silhouette.speed = 0.65f;
		FlashbackTextbox.RunText(FlashbackChats[1], 1, 0);
		CutsceneUtils.MoveTransformEaseOut(NoelleChild_Silhouette.transform, new Vector2(26.125f, 23.65f), 5f);
		CutsceneUtils.MoveTransformEaseOut(Flashback_Snowball.transform, new Vector2(26.725f, 23.95f), 5f);
		yield return new WaitForSeconds(1.25f);
		Flashback_Snowball.GetComponent<SpriteRenderer>().sprite = Flashback_SnowballSprites[1];
		yield return new WaitForSeconds(2.5f);
		Flashback_Snowball.GetComponent<SpriteRenderer>().sprite = Flashback_SnowballSprites[2];
		yield return new WaitForSeconds(1.25f);
		Rudy_Silhouette.Play("Beckon_Idle");
		NoelleChild_Silhouette.Play("Idle");
		Flashback_Snow_BallRoll = false;
		yield return new WaitForSeconds(0.65f);
		FlashbackTextbox.RunText(FlashbackChats[1], 2, 0);
		Rudy_Silhouette.Play("Beckon");
		Flashback_Snow_BallRoll = true;
		NoelleChild_Silhouette.Play("Walk");
		NoelleChild_Silhouette.speed = 0.65f;
		CutsceneUtils.MoveTransformEaseOut(NoelleChild_Silhouette.transform, new Vector2(28.125f, 23.65f), 5f);
		CutsceneUtils.MoveTransformEaseOut(Flashback_Snowball.transform, new Vector2(28.725f, 23.95f), 5f);
		yield return new WaitForSeconds(1.25f);
		Flashback_Snowball.GetComponent<SpriteRenderer>().sprite = Flashback_SnowballSprites[3];
		yield return new WaitForSeconds(2.5f);
		Flashback_Snowball.GetComponent<SpriteRenderer>().sprite = Flashback_SnowballSprites[4];
		yield return new WaitForSeconds(1.25f);
		NoelleChild_Silhouette.Play("Idle");
		Flashback_Snow_BallRoll = false;
		yield return new WaitForSeconds(1.25f);
		Rudy_Silhouette.Play("Beckon");
		NoelleChild_Silhouette.Play("Walk");
		Flashback_Snow_BallRoll = true;
		CutsceneUtils.MoveTransformEaseOut(Flashback_Snowball.transform, new Vector2(29.375f, 24.3f), 2.65f);
		yield return new WaitForSeconds(0.25f);
		NoelleChild_Silhouette.Play("Idle");
		Rudy_Silhouette.Play("Kneel_Left");
		FlashbackTextbox.RunText(FlashbackChats[1], 3, 0);
		yield return new WaitForSeconds(2.4f);
		Flashback_Snowball.gameObject.SetActive(value: false);
		Flashback_Snowpile.sprite = Flashback_Snowpile_Sprites[1];
		yield return new WaitForSeconds(2f);
		FlashbackTextbox.RunText(FlashbackChats[1], 4, 0);
		RotateChildNoelleToDirection(Vector2.up);
		CutsceneUtils.MoveTransformLinear(NoelleChild_Silhouette.transform, new Vector2(29.45f, 23.5f), 2f);
		yield return new WaitForSeconds(3.5f);
		Flashback_Snowpile.sprite = Flashback_Snowpile_Sprites[2];
		RotateChildNoelleToDirection(Vector2.right);
		CutsceneUtils.MoveTransformLinear(NoelleChild_Silhouette.transform, new Vector2(28.25f, 23.35f), 1f);
		yield return new WaitForSeconds(1.5f);
		FlashbackTextbox.RunText(FlashbackChats[1], 5, 0);
		yield return new WaitForSeconds(1.5f);
		Rudy_Silhouette.Play("Kneel_Right");
		yield return new WaitForSeconds(1f);
		Rudy_Silhouette.Play("Pickup_Right");
		Rudy_Silhouette.transform.position = new Vector2(31.375f, 23.65f);
		yield return null;
		CutsceneUtils.ShakeTransform(Rudy_Silhouette.transform, 0.2f, 1f);
		yield return new WaitForSeconds(1f);
		Flashback_Stick1.gameObject.SetActive(value: false);
		Flashback_Stick2.gameObject.SetActive(value: false);
		Rudy_Silhouette.Play("Kneel_Left");
		yield return new WaitForSeconds(0.25f);
		FlashbackTextbox.RunText(FlashbackChats[1], 6, 0);
		CutsceneUtils.MoveTransformLinear(Rudy_Silhouette.transform, new Vector2(30.475f, 23.5f), 1.5f);
		yield return new WaitForSeconds(2.25f);
		Rudy_Silhouette.Play("KneelPlace");
		Flashback_Stick1.transform.rotation = Quaternion.Euler(Vector3.zero);
		Flashback_Stick2.transform.rotation = Quaternion.Euler(Vector3.zero);
		Flashback_Stick1.transform.position = new Vector2(29f, 24.975f);
		Flashback_Stick2.transform.position = new Vector2(29.975f, 24.825f);
		Flashback_Stick1.gameObject.SetActive(value: true);
		Flashback_Stick2.gameObject.SetActive(value: true);
		yield return new WaitForSeconds(1.5f);
		Rudy_Silhouette.Play("Kneel_Left");
		RotateRudyToDirection(Vector2.left);
		CutsceneUtils.MoveTransformLinear(Rudy_Silhouette.transform, new Vector2(30.825f, 23.65f), 0.5f);
		yield return new WaitForSeconds(0.5f);
		Rudy_Silhouette.Play("Idle");
		Flashback_SnowParticle.Stop();
		yield return new WaitForSeconds(0.5f);
		Rudy_Silhouette.Play("Cheer");
		for (int j = 0; j < 4; j++)
		{
			RotateChildNoelleToDirection(Vector2.down);
			NoelleChild_Silhouette.Play("Cheer");
			CutsceneUtils.MoveTransformOnArc(NoelleChild_Silhouette.transform, NoelleChild_Silhouette.transform.position, 1f, 1f);
			yield return new WaitForSeconds(1f);
		}
		CutsceneUtils.MoveTransformOnArc(NoelleChild_Silhouette.transform, NoelleChild_Silhouette.transform.position, 1f, 1f);
		CutsceneUtils.FadeOutSprite(NoelleChild_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		CutsceneUtils.FadeOutSprite(Rudy_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		flashback_Snow = Flashback_Snow;
		for (int i = 0; i < flashback_Snow.Length; i++)
		{
			CutsceneUtils.FadeOutSprite(flashback_Snow[i], 2f);
		}
		yield return new WaitForSeconds(2f);
		FlashbackTextbox.EndText();
		Flashback_SnowParticle.gameObject.SetActive(value: false);
		Flashback_Snow_Holder.gameObject.SetActive(value: false);
		StartCoroutine(Flashback_Intermission1());
	}

	private IEnumerator Flashback_Intermission1()
	{
		while (!Mathf.Approximately(FlashbackMusicSource.volume, 0.4f))
		{
			yield return null;
			FlashbackMusicSource.volume = Mathf.MoveTowards(FlashbackMusicSource.volume, 0.4f, 0.4f * Time.deltaTime);
		}
		CutsceneUtils.RunFreshChat(CutsceneChats[1], 0, ForcePosition: true, OnBottom: true);
		while (ChatboxManager.Instance.ChatIsCurrentlyRunning)
		{
			yield return null;
		}
		while (!Mathf.Approximately(FlashbackMusicSource.volume, 0.667f))
		{
			yield return null;
			FlashbackMusicSource.volume = Mathf.MoveTowards(FlashbackMusicSource.volume, 0.667f, 0.667f * Time.deltaTime);
		}
		yield return new WaitForSeconds(1f);
		FlashbackTextbox.RunText(FlashbackChats[2], 0, 0);
		yield return new WaitForSeconds(4.5f);
		FlashbackTextbox.RunText(FlashbackChats[2], 1, 0);
		yield return new WaitForSeconds(4.5f);
		FlashbackTextbox.EndText();
		StartCoroutine(Cutscene_Flashback_Home());
	}

	private IEnumerator Cutscene_Flashback_Home()
	{
		yield return null;
		SpriteRenderer[] flashback_Home = Flashback_Home;
		for (int i = 0; i < flashback_Home.Length; i++)
		{
			CutsceneUtils.FadeInSprite(flashback_Home[i], 2f);
		}
		CutsceneUtils.FadeInSprite(NoelleChild_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		CutsceneUtils.FadeInSprite(Rudy_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		playerCamera.transform.position = new Vector3(26.925f, 40f, -10f);
		NoelleChild_Silhouette.transform.position = new Vector2(17.775f, 38.45f);
		NoelleChild_Silhouette.Play("PreTeen_Walk");
		RotateChildNoelleToDirection(Vector2.right);
		Rudy_Silhouette.transform.position = new Vector2(28.85f, 39f);
		Rudy_Silhouette.Play("Table_Idle");
		CutsceneUtils.MoveTransformLinear(NoelleChild_Silhouette.transform, new Vector2(24.325f, 38.45f), 3f);
		yield return new WaitForSeconds(2f);
		FlashbackTextbox.RunText(FlashbackChats[3], 0, 0);
		yield return new WaitForSeconds(1f);
		NoelleChild_Silhouette.Play("PreTeen_Idle");
		yield return new WaitForSeconds(1f);
		NoelleChild_Silhouette.Play("PreTeen_Walk");
		CutsceneUtils.MoveTransformLinear(NoelleChild_Silhouette.transform, new Vector2(27.625f, 38.45f), 2f);
		yield return new WaitForSeconds(2f);
		NoelleChild_Silhouette.Play("PreTeen_Idle");
		yield return new WaitForSeconds(0.5f);
		RotateChildNoelleToDirection(Vector2.up);
		FlashbackTextbox.RunText(FlashbackChats[3], 1, 0);
		yield return new WaitForSeconds(4f);
		FlashbackTextbox.RunText(FlashbackChats[3], 2, 0);
		Rudy_Silhouette.Play("Table_Tense");
		yield return new WaitForSeconds(4f);
		FlashbackTextbox.RunText(FlashbackChats[3], 3, 0);
		Rudy_Silhouette.Play("Table_Idle");
		yield return new WaitForSeconds(4f);
		FlashbackTextbox.RunText(FlashbackChats[3], 4, 0);
		Rudy_Silhouette.Play("Table_Tense");
		yield return new WaitForSeconds(4.25f);
		FlashbackTextbox.RunText(FlashbackChats[3], 5, 0);
		yield return new WaitForSeconds(3.75f);
		FlashbackTextbox.RunText(FlashbackChats[3], 6, 0);
		yield return new WaitForSeconds(6.5f);
		FlashbackTextbox.RunText(FlashbackChats[3], 7, 0);
		Rudy_Silhouette.Play("Table_Idle");
		yield return new WaitForSeconds(4f);
		Rudy_Silhouette.Play("Table_Hit");
		CutsceneUtils.MoveTransformLinear(NoelleChild_Silhouette.transform, new Vector2(26.275f, 38.45f), 1f);
		NoelleChild_Silhouette.Play("PreTeen_Walk");
		RotateChildNoelleToDirection(Vector2.right);
		yield return new WaitForSeconds(1f);
		NoelleChild_Silhouette.Play("PreTeen_Idle");
		yield return new WaitForSeconds(1.4f);
		RotateChildNoelleToDirection(Vector2.down);
		CutsceneUtils.ShakeTransform(NoelleChild_Silhouette.transform, 0.2f, 1f);
		Rudy_Silhouette.Play("Table_Cry");
		yield return new WaitForSeconds(1.5f);
		CutsceneUtils.ShakeTransform(NoelleChild_Silhouette.transform, 0.2f, 1f);
		NoelleChild_Silhouette.Play("PreTeen_CryIdle");
		yield return new WaitForSeconds(2f);
		NoelleChild_Silhouette.Play("PreTeen_Cry");
		FlashbackTextbox.RunText(FlashbackChats[3], 8, 0);
		yield return new WaitForSeconds(4f);
		FlashbackTextbox.EndText();
		CutsceneUtils.FadeOutSprite(NoelleChild_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		CutsceneUtils.FadeOutSprite(Rudy_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		flashback_Home = Flashback_Home;
		for (int i = 0; i < flashback_Home.Length; i++)
		{
			CutsceneUtils.FadeOutSprite(flashback_Home[i], 2f);
		}
		yield return new WaitForSeconds(2f);
		FlashbackTextbox.RunText(FlashbackChats[3], 9, 0);
		yield return new WaitForSeconds(4f);
		FlashbackTextbox.EndText();
		StartCoroutine(Cutscene_Flashback_Bed());
	}

	private IEnumerator Cutscene_Flashback_Bed()
	{
		yield return null;
		SpriteRenderer[] flashback_Bed = Flashback_Bed;
		for (int i = 0; i < flashback_Bed.Length; i++)
		{
			CutsceneUtils.FadeInSprite(flashback_Bed[i], 2f);
		}
		CutsceneUtils.FadeInSprite(NoelleChild_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		CutsceneUtils.FadeInSprite(Rudy_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		playerCamera.transform.position = new Vector3(26.925f, 60f, -10f);
		NoelleChild_Silhouette.transform.position = new Vector2(26.925f, 61.15f);
		NoelleChild_Silhouette.Play("SatBed_Idle");
		RotateChildNoelleToDirection(Vector2.down);
		Rudy_Silhouette.transform.position = new Vector2(26.275f, 62.025f);
		Rudy_Silhouette.Play("Bed_HoldShoulder");
		RotateRudyToDirection(Vector2.down);
		yield return new WaitForSeconds(2f);
		FlashbackTextbox.RunText(FlashbackChats[4], 0, 0);
		yield return new WaitForSeconds(4.5f);
		FlashbackTextbox.RunText(FlashbackChats[4], 1, 0);
		yield return new WaitForSeconds(4.5f);
		FlashbackTextbox.RunText(FlashbackChats[4], 2, 0);
		yield return new WaitForSeconds(6f);
		Rudy_Silhouette.Play("Bed_Idle");
		NoelleChild_Silhouette.Play("SatBed_IdleLeft");
		FlashbackTextbox.RunText(FlashbackChats[4], 3, 0);
		yield return new WaitForSeconds(5f);
		Rudy_Silhouette.Play("Bed_LeanRight");
		FlashbackTextbox.RunText(FlashbackChats[4], 4, 0);
		yield return new WaitForSeconds(5f);
		Rudy_Silhouette.Play("Bed_HoldShoulder");
		NoelleChild_Silhouette.Play("SatBed_Idle");
		FlashbackTextbox.RunText(FlashbackChats[4], 5, 0);
		yield return new WaitForSeconds(5.5f);
		FlashbackTextbox.RunText(FlashbackChats[4], 6, 0);
		Rudy_Silhouette.Play("Bed_LeanLeft");
		CutsceneUtils.ShakeTransform(Rudy_Silhouette.transform, 0.25f, 1f);
		yield return new WaitForSeconds(1f);
		Rudy_Silhouette.Play("Idle");
		RotateRudyToDirection(Vector2.down);
		Rudy_Silhouette.transform.position = new Vector2(26.175f, 60.175f);
		CutsceneUtils.ShakeTransform(Rudy_Silhouette.transform, 0.25f, 1f);
		yield return new WaitForSeconds(1f);
		RotateRudyToDirection(Vector2.left);
		Rudy_Silhouette.speed = 0.75f;
		Rudy_Silhouette.Play("Walk");
		CutsceneUtils.MoveTransformLinear(Rudy_Silhouette.transform, new Vector2(17.5f, 60.175f), 3.5f);
		yield return new WaitForSeconds(3.5f);
		FlashbackTextbox.RunText(FlashbackChats[4], 7, 0);
		yield return new WaitForSeconds(3.65f);
		FlashbackTextbox.RunText(FlashbackChats[4], 8, 0);
		RotateRudyToDirection(Vector2.right);
		CutsceneUtils.MoveTransformLinear(Rudy_Silhouette.transform, new Vector2(26.7f, 60.175f), 3.5f);
		yield return new WaitForSeconds(3.5f);
		Rudy_Silhouette.speed = 1f;
		Rudy_Silhouette.Play("IdleGuitar");
		yield return new WaitForSeconds(1f);
		Flashback_Bed_NoelleGuitarArms.gameObject.SetActive(value: true);
		NoelleChild_Silhouette.Play("SatBed_Armless");
		Rudy_Silhouette.Play("Idle");
		RotateRudyToDirection(Vector2.up);
		yield return new WaitForSeconds(1.25f);
		RotateRudyToDirection(Vector2.right);
		CutsceneUtils.MoveTransformLinear(Rudy_Silhouette.transform, new Vector2(26.175f, 60.175f), 0.75f);
		yield return new WaitForSeconds(0.75f);
		Flashback_Bed_NoelleGuitarArms.GetComponent<SpriteRenderer>().sortingOrder = 4;
		Rudy_Silhouette.Play("Bed_LeanLeft");
		Rudy_Silhouette.transform.position = new Vector2(26.275f, 62.025f);
		CutsceneUtils.ShakeTransform(Rudy_Silhouette.transform, 0.25f, 0.5f);
		yield return new WaitForSeconds(0.5f);
		Rudy_Silhouette.Play("Bed_Idle");
		yield return new WaitForSeconds(0.5f);
		Rudy_Silhouette.Play("Bed_HoldShoulder");
		yield return new WaitForSeconds(0.35f);
		FlashbackTextbox.RunText(FlashbackChats[4], 9, 0);
		yield return new WaitForSeconds(3f);
		FlashbackTextbox.EndText();
		Flashback_Bed_NoelleGuitarArms.GetComponent<SpriteRenderer>().sprite = Flashback_Bed_GuitarSprite;
		CutsceneUtils.PlaySound(CutsceneSounds[0], CutsceneUtils.DRH_MixerChannels.Effect, 1.25f);
		yield return new WaitForSeconds(3f);
		CutsceneUtils.FadeOutSprite(NoelleChild_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		CutsceneUtils.FadeOutSprite(Rudy_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		CutsceneUtils.FadeOutSprite(Flashback_Bed_NoelleGuitarArms.GetComponent<SpriteRenderer>(), 2f);
		flashback_Bed = Flashback_Bed;
		for (int i = 0; i < flashback_Bed.Length; i++)
		{
			CutsceneUtils.FadeOutSprite(flashback_Bed[i], 2f);
		}
		yield return new WaitForSeconds(2f);
		StartCoroutine(Cutscene_Flashback_PresentDay());
	}

	private IEnumerator Cutscene_Flashback_PresentDay()
	{
		yield return null;
		IncrementRudySkinChange();
		OriginalNoelle_Silhouette.gameObject.GetComponent<SPR_CopyPosition>().enabled = true;
		SpriteRenderer[] flashback_PresentDay = Flashback_PresentDay;
		for (int i = 0; i < flashback_PresentDay.Length; i++)
		{
			CutsceneUtils.FadeInSprite(flashback_PresentDay[i], 2f);
		}
		CutsceneUtils.FadeInSprite(OriginalNoelle_Silhouette.Renderer, 2f);
		CutsceneUtils.FadeInSprite(Rudy_Silhouette.GetComponent<SpriteRenderer>(), 2f);
		playerCamera.transform.position = new Vector3(26.925f, 78f, -10f);
		OriginalNoelle.transform.position = new Vector2(28.95f, 79.85f);
		OriginalNoelle.Play("TRB_Flashback_HoldHand");
		RotateNoelleToDirection(Vector2.left);
		Rudy_Silhouette.transform.position = new Vector2(27.9f, 80.95f);
		Rudy_Silhouette.Play("Hospital_HoldHand");
		while (!Mathf.Approximately(FlashbackMusicSource.volume, 0.4f))
		{
			yield return null;
			FlashbackMusicSource.volume = Mathf.MoveTowards(FlashbackMusicSource.volume, 0.4f, 0.4f * Time.deltaTime);
		}
		CutsceneUtils.RunFreshChat(CutsceneChats[2], 0, ForcePosition: true, OnBottom: true);
		while (ChatboxManager.Instance.ChatIsCurrentlyRunning)
		{
			yield return null;
		}
		yield return new WaitForSeconds(1.5f);
		CutsceneUtils.RunFreshChat(CutsceneChats[2], 1, ForcePosition: true, OnBottom: true);
		while (ChatboxManager.Instance.ChatIsCurrentlyRunning)
		{
			yield return null;
		}
		yield return new WaitForSeconds(1f);
		NoelleRudy_PlaceHead();
		FlashbackTextbox.CurrentTextSpeedMultiplier = 1.25f;
		FlashbackTextbox.RunText(FlashbackChats[5], 0, 0);
		CutsceneUtils.PlaySound(CutsceneSounds[7], CutsceneUtils.DRH_MixerChannels.Effect, 0.5f);
		MusicManager.StopSong(Fade: true, 1f, FlashbackMusicSource);
		yield return new WaitForSeconds(4f);
		Rudy_Silhouette.Play("Hospital_AboutToDie");
		OriginalNoelle.speed = 0.4f;
		OriginalNoelle.Play("TRB_WalkHorror");
		CutsceneUtils.MoveTransformLinear(OriginalNoelle.transform, new Vector2(29.25f, 79.85f), 2f);
		yield return new WaitForSeconds(2f);
		OriginalNoelle.speed = 1f;
		OriginalNoelle.Play("TRB_IdleHorror");
		FlashbackTextbox.CurrentTextSpeedMultiplier = 2f;
		FlashbackTextbox.RunText(FlashbackChats[5], 1, 0);
		yield return new WaitForSeconds(3f);
		Rudy_Silhouette.Play("Hospital_FlopOverDeadRip");
		CutsceneUtils.PlaySound(CutsceneSounds[6], CutsceneUtils.DRH_MixerChannels.Effect, 0.15f, 0.6f);
		yield return new WaitForSeconds(2f);
		FlashbackTextbox.EndText();
		yield return new WaitForSeconds(7f);
		HospitalLobbyCutscene.gameObject.SetActive(value: true);
		HospitalLobbyCutscene.StartCoroutine("Cutscene_Aftermath");
		Fade_Background.gameObject.SetActive(value: false);
		yield return new WaitForSeconds(1f);
		NoelleChild_Silhouette.gameObject.SetActive(value: false);
		OriginalNoelle_Silhouette.gameObject.SetActive(value: false);
		base.gameObject.SetActive(value: false);
	}

	public IEnumerator Cutscene_Finale()
	{
		yield return null;
		CutsceneUtils.RunFreshChat(CutsceneChats[3], 0, ForcePosition: true, OnBottom: true);
		while (ChatboxManager.Instance.ChatIsCurrentlyRunning)
		{
			yield return null;
		}
		StartCoroutine(OpenFountain());
	}

	private IEnumerator OpenFountain()
	{
		yield return null;
		CameraManager.instance.transform.position = new Vector3(60f, 30f, -10f);
		int pitchindex = 0;
		GameObject[] fountainTargetParticles = FountainTargetParticles;
		foreach (GameObject obj in fountainTargetParticles)
		{
			pitchindex++;
			yield return new WaitForSeconds(0.03f);
			float pitch = Mathf.Lerp(1f, 2f, (pitchindex - 1) / 23);
			CutsceneUtils.PlaySound(CutsceneSounds[4], CutsceneUtils.DRH_MixerChannels.Effect, 2f, pitch);
			obj.SetActive(value: true);
		}
		Fountain_AngelHalo.Play("TRB_AngelHalo_Open");
		CutsceneUtils.PlaySound(CutsceneSounds[5], CutsceneUtils.DRH_MixerChannels.Effect, 2f, 1.25f);
		yield return new WaitForSeconds(1f);
		CameraManager.instance.transform.position = new Vector3(60f, 0f, -10f);
		CutsceneUtils.PlaySound(CutsceneSounds[2]);
		OriginalNoelle.gameObject.SetActive(value: true);
		OriginalNoelle.transform.position = new Vector2(60.25f, -2.9f);
		OriginalNoelle.Play("TRB_HospitalFinale_FountainOpenStab");
		yield return new WaitForSeconds(0.267f);
		OriginalNoelle.Play("TRB_HospitalFinale_FountainOpenLoop");
		Fountain_Noelle_Lit.Play("TRB_HospitalFinale_FountainOpenLoop");
		Fountain_Noelle_unlit.Play("TRB_HospitalFinale_FountainOpenInverted");
		MusicManager.PlaySong(mus_rumbling, FadePreviousSong: true, 20f);
		Fountain_InitialLight.Play("TRB_FountainOpen_InitialLight");
		CutsceneUtils.PlaySound(CutsceneSounds[1]);
		CutsceneUtils.PlaySound(CutsceneSounds[3]);
		CutsceneUtils.FadeInSprite(Finale_BackgroundFlash);
		yield return new WaitForSeconds(0.2f);
		CutsceneUtils.FadeInSprite(Fountain_Noelle_Lit.GetComponent<SpriteRenderer>());
		Fountain_CrackParticles.gameObject.SetActive(value: true);
		yield return new WaitForSeconds(3f);
		CutsceneUtils.FadeSpriteToColor(Fountain_InnerBeam, Color.black);
		CutsceneUtils.FadeInSprite(Fountain_Noelle_unlit.GetComponent<SpriteRenderer>());
		yield return new WaitForSeconds(4f);
		CutsceneUtils.FadeInSprite(HospitalLobbyCutscene.Fade_Hacky, 2f);
		StartCoroutine(EndingStoryPanel());
	}

	private IEnumerator EndingStoryPanel()
	{
		yield return new WaitForSeconds(7f);
		CameraManager.instance.transform.position = new Vector3(90f, 0f, -10f);
		yield return null;
		CutsceneUtils.FadeOutSprite(HospitalLobbyCutscene.Fade_Hacky, 2f);
		yield return new WaitForSeconds(1f);
		GasterText.RunText(EndingText, 0, 0);
		yield return new WaitForSeconds(5.5f);
		GasterText.RunText(EndingText, 1, 0);
		yield return new WaitForSeconds(5f);
		CutsceneUtils.FadeInSprite(StoryPanel_Fade);
		yield return new WaitForSeconds(1f);
		GasterText.RunText(EndingText, 2, 0);
		CutsceneUtils.ShakeTransform(StoryPanel_Background.transform);
		StoryPanel_Fountain.SetActive(value: true);
		CutsceneUtils.FadeOutSprite(StoryPanel_Fade);
		yield return new WaitForSeconds(4f);
		GasterText.RunText(EndingText, 3, 0);
		CutsceneUtils.MoveTransformSmooth(StoryPanel_Background.transform, new Vector2(90f, -3.05f), 4f);
		yield return new WaitForSeconds(6f);
		GasterText.RunText(EndingText, 4, 0);
		StoryPanel_Background.sprite = StoryPanel_Background_Inverted;
		CutsceneUtils.MoveTransformSmooth(StoryPanel_Background.transform, new Vector2(90f, 6f), 4f);
		CutsceneUtils.MoveTransformSmooth(StoryPanel_DarknessBubbles, new Vector2(90f, -14.25f), 9f);
		yield return new WaitForSeconds(8f);
		GasterText.RunText(EndingText, 5, 0);
		yield return new WaitForSeconds(4f);
		MusicManager.StopSong(Fade: true, 1f);
		yield return new WaitForSeconds(2f);
		UI_FADE.Instance.StartFadeIn(37, 0.333f, UnpauseOnEnd: true);
	}

	private void RotateNoelleToDirection(Vector2 direction)
	{
		CutsceneUtils.RotateCharacterToDirection(OriginalNoelle, "VelocityX", "VelocityY", direction);
	}

	private void RotateChildNoelleToDirection(Vector2 direction)
	{
		CutsceneUtils.RotateCharacterToDirection(NoelleChild_Silhouette, "VelocityX", "VelocityY", direction);
	}

	private void RotateRudyToDirection(Vector2 direction)
	{
		CutsceneUtils.RotateCharacterToDirection(Rudy_Silhouette, "VelocityX", "VelocityY", direction);
	}

	public void IncrementRudySkinChange()
	{
		Rudy_Silhouette.GetComponent<SpriteRenderer>().color = RudySkinPale_Colors[RudySkinIndex];
		if (RudySkinIndex > 0)
		{
			FlashbackMusicSource.pitch -= 0.01f;
		}
		RudySkinIndex++;
	}

	public void NoelleRudy_Tense()
	{
		Rudy_Silhouette.Play("Hospital_Closer");
		OriginalNoelle.Play("TRB_Flashback_Tense");
	}

	public void NoelleRudy_HoldHand()
	{
		Rudy_Silhouette.Play("Hospital_HoldHand");
		OriginalNoelle.Play("TRB_Flashback_HoldHand");
	}

	public void NoelleRudy_PlaceHead()
	{
		Rudy_Silhouette.Play("Hospital_PlaceHead");
		OriginalNoelle.Play("TRB_Flashback_PlaceHead");
	}
}
